package com.cy.pj.sys.controller;

import com.cy.pj.sys.pojo.SysUser;
import com.cy.pj.sys.pojo.SysUserMenu;
import com.cy.pj.sys.service.SysMenuService;
import com.sun.org.apache.xml.internal.serializer.AttributesImplSerializer;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
@RequestMapping("/")
public class PageController {


    @RequestMapping("doLoginUI")
    public String doLoginUI(){
        return "login";
    }

    @Autowired
    private SysMenuService sysMenuService;
    @RequestMapping("doIndexUI")
    public String doIndexUI(Model model){
        SysUser user=(SysUser) SecurityUtils.getSubject().getPrincipal();
        String username=user.getUsername();
        model.addAttribute("username",username);
        List<SysUserMenu> userMenus=sysMenuService.findUserMenusByUserId(user.getId());
        model.addAttribute("userMenus",userMenus);

        return "starter";
    }
    @RequestMapping("doPageUI")
    public String doPageUI() {
        return "common/page";
    }
  /*  @RequestMapping("log/log_list")
    public String doLogUI() {
        return "sys/log_list";
    }
    @RequestMapping("menu/menu_list")
    public String doMenuUI() {
        return "sys/menu_list";
    }
   */
    //rest风格url，简化view
    @RequestMapping("{module}/{moduleUI}")
    public String doModuleUI(@PathVariable String moduleUI) {
       return "sys/"+moduleUI;
    }
}

